import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
	songIdList:[],
	nextSongId:'',
	previousSongId: '',
	previousAodioIns: '',	
	wxMenuObj: {width: 87, height: 32, left: 320, top: 24, right: 407,bottom: 56},
	sysInfo: {},
	cureentPlayInsTimer: [],
	
}

const mutations = {
	idList(state, payload) {
		state.songIdList = payload
	},
	nextId(state,songId) {
		console.log("下一首id是"+ songId)
		for(let i=0; i < state.songIdList.length; i++) {
			if(state.songIdList[i].id == songId){ 
				state.nextSongId = state.songIdList[i+1].id
			}
		}
	},
	
	setPreviousSongId(state, songId) {
		state.previousSongId = songId
	}
	,
	addAodioIns(state,AodioIns) {
		console.log(AodioIns)
		state.previousAodioIns = AodioIns
	},
	setwxMenuObj(state, menuObj) {
		state.wxMenuObj = menuObj
	},
	setSysInfo(state, sysInfo) {
		console.log(sysInfo)
		state.sysInfo = sysInfo
	},
	setcureentPlayInsTimer(state, timerList){
		state.cureentPlayInsTimer = timerList
	}
}

const getters = {
	getNextSongId(state) {
		return state.nextSongId
	},
	getPreviousAodioIns(state) {
		return state.previousAodioIns
	},
	WxMenuObj(state) {
		return state.wxMenuObj
	},
	navHeight(state) { //自定义导航栏高度
		
		return state.wxMenuObj.bottom
		
	},
	canScrollHeight(state, getters) { //可滚动区域高度
		let changePx = state.sysInfo.statusBarHeight >= 44 ? 8 : 0
		return state.sysInfo.windowHeight - getters.navHeight  - changePx
	},
	previousSongId(state) {
		return state.previousSongId
	},
	sysInfo(state) {
		return state.sysInfo
	},
	cureentPlayInsTimer(state) {
		return state.cureentPlayInsTimer
	}
}

const store = new Vuex.Store({
	state,
	mutations,
	getters,
})


export default  store